package com.humanminoritygame;
/*
 * Copyright (c) 2008 IT - ITBA -- All rights reserved
 */ 


import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.hibernate.dialect.Dialect;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean;

/**
 * Creates an SQL dump of the DDLs required to build the schema mapped by Hibernate
 */
public class DumpSchema {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		BasicConfigurator.configure();
		Logger.getRootLogger().setLevel(Level.INFO);
		ApplicationContext ctx = new FileSystemXmlApplicationContext("src/main/webapp/WEB-INF/dispatcher-servlet.xml");

		AnnotationSessionFactoryBean factory = (AnnotationSessionFactoryBean) ctx.getBean("&sessionFactory");

		Dialect dialect = Dialect.getDialect(factory.getConfiguration().getProperties());
		String[] sql = factory.getConfiguration().generateSchemaCreationScript(dialect);
		for (String line : sql) {
			System.out.println(line + ";");
		}
	}
}
